<?php
require_once './config.php';

$username = $_REQUEST['username'];
$password = $_REQUEST['password'];

// 注册

$sql = "SELECT * from denglu WHERE username = '$username'";

$result = mysqli_query($conn, $sql);

$data = mysqli_fetch_assoc($result);

// var_dump($data);

if ($data) { // 用户名存在
    echo json_encode(array(
        'code' => 0,
        'msg' => '用户名已存在',
    ));
} else {
    $sql = "INSERT INTO denglu (username, password) VALUES ('$username', '$password')";

    mysqli_query($conn, $sql); // 受影响行数

    $rows = mysqli_affected_rows($conn); // 受影响行数

    if ($rows > 0) {
        echo json_encode(array(
            'code' => 1,
            'msg' => '注册成功',
        ));
    }

}
